﻿using EventBus;
using LiteStep.Currencies;
using LiteStep.Events;
using LiteStep.Events.Handlers;
using LiteStep.Exchanges.BtcE;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LiteStep.Console
{
	public class BtcETickerWriter<TFrom, TTo> : IAfterTickerResponseEventHandler<Ticker<TFrom, TTo>>
		where TFrom : ICurrency<TFrom>, new()
		where TTo : ICurrency<TTo>, new()
	{
		public BtcETickerWriter(IEventBus eventBus)
		{
			eventBus.AddHandler(AfterTickerResponseEvent<Ticker<TFrom, TTo>>.TYPE, this);
		}

		public void OnAfterTickerResponseEvent(AfterTickerResponseEvent<Ticker<TFrom, TTo>> e)
		{
			if (e == null || e.Ticker == null)
			{
				System.Console.WriteLine(String.Format("Btc-e\t| Error getting {0}/{1} ticker", typeof(TFrom).Name.ToUpper(), typeof(TTo).Name.ToUpper())); 
				return; 
			}

			System.Console.WriteLine(String.Format("Btc-e\t{0}/{1}\t| {2}", typeof(TFrom).Name.ToUpper(), typeof(TTo).Name.ToUpper(), e.Ticker));
		}
	}
}
